<!--#INCLUDE FILE="config.asp"-->
<%
dim filename
filename = replace(replace(replace(replace(now,"/",""),":",""),"-","")," ","")&".csv"
Dim uploadObj
'Create an instance of our SmartUpload object.
Set uploadObj = Server.CreateObject("aspSmartUpload.SmartUpload")
uploadObj.AllowedFilesList = "csv"
uploadObj.TotalMaxFileSize = 20000000
'Process the upload
on error resume next
uploadObj.Upload
response.write "errnumber"&Err.number
if Err.number = -2147220494 then
	errmsg = "wtyp"
else
On Error GoTo 0
	errmsg = "upd"



For each file In uploadObj.Files
   '  Only if the file exist
   '  **********************
      If not file.IsMissing Then

      '  Add the current file in a DB field
      '  **********************************
        
          file.saveas server.MapPath("Upload/"&filename)
          curfilename = server.MapPath("Upload/"&filename)

          
      End If
Next
strPathtoCSVFile=server.MapPath("Upload\")
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathtoCSVFile & ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
RS.Open "SELECT * FROM "&filename, Conn, 1, 3, &H0001

redim FieldNames(rs.fields.count)
redim FieldTypes(rs.fields.count)
For i = 0 To (rs.Fields.Count - 1)
    FieldNames(i) = cstr(trim(rs.Fields.Item(i).Name))
    FieldTypes(i) = cstr(trim(rs.Fields.Item(i).Type))
	
Next
RS.Close
RS.Open "SELECT * FROM "&filename, Conn, 3, 3, &H0001
'Response.Write "<br>null" & isnull(RS(FieldNames(0))) & "<br>"
'Response.End()
i = 0
if not RS.eof then	
while not(RS.eof) and not(isnull(RS(FieldNames(0))))
i = i + 1
'response.write i & "<br>"
'Do Until RS.EOF
		set objConnect = server.createObject("ADODB.Connection")       
		objConnect.open conStr
		set rss = Server.CreateObject("ADODB.Recordset")
		'response.write 	"EXEC sp_update_bookingsstatus "&RS(FieldNames(0))
		rss.Open "EXEC sp_addnew_Codes '"&RS(FieldNames(0))&"','"&RS(FieldNames(1))&"','"&RS(FieldNames(2))&"','"&RS(FieldNames(3))&"',"&RS(FieldNames(4))&","&RS(FieldNames(5))&",'"&RS(FieldNames(6))&"','"&RS(FieldNames(7))&"','"&RS(FieldNames(8))&"','"&RS(FieldNames(9))&"',"&RS(FieldNames(10))&","&RS(FieldNames(11))&","&RS(FieldNames(12))&",'"&RS(FieldNames(13))&"','"&RS(FieldNames(14))&"'",objConnect
		'rss.close()
		
	
	RS.movenext
	wend
end if
'RS.MoveNext
'Loop
RS.Close
Conn.Close
end if
Response.Redirect("costabaja-upload-codes.asp?msg="&errmsg&"&filename="&curfilename )
%>